package com.itcast.googleplay.adapter;

import java.util.List;
import com.itcast.googleplay.holder.BaseHolder;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.CycleInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.BaseAdapter;

public abstract class MyBaseAdapter<T> extends BaseAdapter{
	public List<T> list;
	private BaseHolder holder;
	public int currentPosition;

	public MyBaseAdapter(List<T> list) {
		//T 泛型  任意类型
		this.list = list;
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public T getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	//返回listView中一个条目的view对象,并且给其附上数据
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		currentPosition = position;
		if(convertView == null){
			holder = getSubBaseholder();
		}else{
			holder = (BaseHolder) convertView.getTag();
		}
		holder.setData(list.get(position));
		
		//1.获取执行动画的convertView
		View view = holder.getConvertView();
		//2.属性动画让view能够实现一个放大的效果(0.5f-1.0f)
		//2.1指定起始控件大小(0.5f------>1.0f)
		ViewHelper.setScaleX(view,0.5f);
		ViewHelper.setScaleY(view,0.5f);
		//2.2
		ViewPropertyAnimator.animate(view).scaleX(1.0f).setDuration(350)
//		Interpolator插值器(动画变化曲线(匀速动画,加速动画...))
		.setInterpolator(new OvershootInterpolator())
		.start();
		
		ViewPropertyAnimator.animate(view).scaleY(1.0f).setDuration(350)
		//Interpolator插值器(动画变化曲线(匀速动画,加速动画...))
		.setInterpolator(new OvershootInterpolator())
		.start();

		return holder.getConvertView();
	}
	//在父类的数据适配器中,不知道子类的holder具体的对象的类型,所以抽象
	
	//此方法中需要返回一个BaseHolder的子类对象
	public abstract BaseHolder getSubBaseholder() ;
}
